<?php
namespace app\hotback\controller;
use think\Db;
class Area extends Base
{
	public function _initialize()
	{
		// 调用父类前置方法
		parent::_initialize();
		// 登录校验
		$this->IsLogin();
	}

	/**
	 * 地区列表
	 */
	public function index()
	{
		$result['code'] = -1;
		$result['msg'] = "非法请求";
		if(request()->isPost())
		{
			$params = input();
			$map = [];
			if(!empty($params['name']))
			{
				$map['name'] = ['like','%'.$params['name'].'%'];
			}
			$count = Db::name('area')->where($map)->count();
			$list_data = Db::name('area')->where($map)->order('id asc')->select();
			if(!empty($list_data))
			{
				$result['code'] = 0;
        		$result['msg'] = "请求成功";
        		$result['data'] = $list_data;
        		$result['count'] = $count;
			}else
			{
				$result['code'] = -1;
	        	$result['msg'] = "暂无数据";
			}
			//echo json_encode($result);
			return json($result);
		}else
		{
			return $this->fetch();
		}
	}
}